import unittest

from login_function import login, login_func

from parameterized import parameterized

# from test_cacheout import cache1

cases = [(0, 'admin', '123456'), [3, 'admin', '123123'], (2, 'admin', '')]  # 注意组织测试数据时，要用列表，同时元素必须是列表或是元组


class Testwork1(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        print('类初始化方法，只运行一次，而且最先执行')

    @classmethod
    def tearDownClass(cls) -> None:
        print('类清除方法，只运行一次，而且最后执行')

    def setUp(self) -> None:
        print('运行初始化方法')

    def tearDown(self) -> None:
        print('运行清除方法')

    def test_method1(self):
        login('admin', '123456')

    def test_method2(self):
        login('root', '123456')

    def test_method3(self):
        login('admin', '123123')

    def test_method4(self):
        login('aaa', '123123')

    @parameterized.expand(cases)
    def test_method5(self, expect_result, username, password):
        self.assertEqual(expect_result, login_func(username, password).get('code'))

    # def test_method6(self):
    #     self.assertEqual(3, login_func('admin', '123123').get('code'))

    # def test_method7(self):
    #     self.assertEqual(2, login_func('admin', '').get('code'))


# print(cache1.get('a'), cache1.get('b'), cache1.get('c'))
